<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #main{
            width: 400px;
            height: 400px;
            text-align: center;
            border: 1px solid #000;
            margin: 0px auto;
            position: relative;
        }

        #box1 {
            width: 100px;
            height: 100px;
            top: 150px; /*静态定位的元素不会受到 top, bottom, left, right影响*/
            left: 150px;
            position: static;
            border: 3px solid #666;
        }

        #box2 {
            width: 100px;
            height: 100px;
            top: 50px;
            left: 50px;
            position: fixed;/*相对于浏览器窗口的固定位置*/
            border: 3px solid lightcoral;
        }

        #box3{
            width: 100px;
            height: 100px;
            top: 20px;
            left: 20px;
            position: absolute;/*由于父容器没有定位，变成相对于浏览器窗口的位置*/
            border: 3px solid lightskyblue;
        }

        #box4{
            width: 100px;
            height: 100px;
            top: 50px;
            left: 50px;
            position: relative;/*相对于其正常位置进行定位*/
            border: 3px solid lightseagreen;
        }


    </style>
</head>
<body>
<h1>Css的定位案例</h1>
<hr>
<!--
 static
 fixed
 relative
 absolute
-->

<div id="main">
    main水平居中
    <div id="box1">
        static
    </div>

    <div id="box2">
        fixed
    </div>

    <div id="box3">
        absolute
    </div>

    <div id="box4">
        relative
    </div>
</div>
</body>
</html>